<?php
$root = $_SERVER['DOCUMENT_ROOT'] . "/php/";

include_once "$root/config/SqlConfig.php";


class SqlConnect
{
    private $sqlName;
    private $sqlUser;
    private $sqlPass;

    /**
     * SqlConnect constructor.
     * @param $sqlName
     * @param $sqlUser
     * @param $sqlPass
     */
    public function __construct()
    {
//        SqlConfig::$SQL_NAME, SqlConfig::$SQL_USER, SqlConfig::$SQL_PASS
        $this->sqlName = SqlConfig::$SQL_NAME;
        $this->sqlUser = SqlConfig::$SQL_USER;
        $this->sqlPass = SqlConfig::$SQL_PASS;
    }

    public function connect(): PDO
    {
        $dbms = "mysql";
        $host = "localhost";
        $dns = "$dbms:host=$host;dbname=$this->sqlName";
        $pdo = null;
        try {
            $pdo = new PDO($dns, $this->sqlUser, $this->sqlPass);
        } catch (PDOException $exception) {
            die($exception);
        }
        return $pdo;
    }
}